package cn.wk.dao.impl;

import cn.wk.dao.AdminsDao;
import cn.wk.dao.StuinfoDao;
import cn.wk.entity.Admins;
import cn.wk.entity.Stuinfo;
import cn.wk.util.JDBCUtil;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class StuinfoDaolmpl implements StuinfoDao {
    private JdbcTemplate template=new JdbcTemplate(JDBCUtil.getDataSource());
    @Override
    public List<Stuinfo> getAllStuinfo(Object...obj) {
        String sql="SELECT stuid,stuno,stupwd,stuname,stugender,stuaddress,stutel,stuemail,c.cname FROM stuinfo s,classes c " +
                " where s.cid=c.cid limit ?,?";
        List<Stuinfo> list=  template.query(sql, new BeanPropertyRowMapper<>(Stuinfo.class),obj);
        return list;
    }
    @Override
    public int  CountSize(){
        String sql="select count(*) from stuinfo";
        int b=template.queryForObject(sql,Integer.class);
        return b;
    }

    @Override
    public int AddStuinfo(Object... obj) {
        String sql="insert stuinfo values(null,?,?,?,?,?,?,?,?)";
        int b=template.update(sql,obj);
        return b;
    }

    @Override
    public int MidffStuinfo(Object... obj) {
        String sql="update stuinfo set stupwd=?,stuname=?,stugender=?,stuaddress=?,stutel=?,stuemail=?,cid=? where stuid=?";
        int b=template.update(sql,obj);
        return b;
    }

    @Override
    public int DelStuinfo(Object... obj) {
       return 0;
    }



    @Override
    public Stuinfo findStuinfoById(int aid) {
        String sql="select * from stuinfo where stuid=?";
      Stuinfo stu=  template.queryForObject(sql,new BeanPropertyRowMapper<>(Stuinfo.class),aid);
        return stu;
    }

    @Override
    public Stuinfo findStuinfoByNo(String no) {
        String sql="select * from stuinfo where stuno=?";
        Stuinfo stu=  template.queryForObject(sql,new BeanPropertyRowMapper<>(Stuinfo.class),no);
        return stu;
    }


}
